package com.wclass.controller.app;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.wclass.common.ReturnObject;
import com.wclass.entity.BaseAbout;
import com.wclass.entity.BaseProgress;
import com.wclass.entity.BaseProgressType;
import com.wclass.interceptor.IgnoreAuth;
import com.wclass.service.IBaseAboutService;
import com.wclass.service.IBaseProgressService;
import com.wclass.service.IBaseProgressTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author SEN
 * @since 2019-02-14
 */
@Api(description = "关于我们")
@RestController
@RequestMapping("/about")
public class AboutController {
    @Autowired
    private IBaseAboutService aboutService;
    @Autowired
    private IBaseProgressService progressService;
    @Autowired
    private IBaseProgressTypeService progressTypeService;

    @IgnoreAuth
    @ApiOperation("获取关于我们详情")
    @RequestMapping(value = "/getAboutUsInfo", method = RequestMethod.POST)
    public ReturnObject<BaseAbout> getAboutUsInfo() {
        return new ReturnObject<>(0, "获取成功", aboutService.selectById(1L));
    }

    @IgnoreAuth
    @ApiOperation("获取相关发展历程")
    @RequestMapping(value = "/getProgressList", method = RequestMethod.POST)
    public ReturnObject<List<BaseProgressType>> getProgressList() {
        EntityWrapper<BaseProgressType> ew = new EntityWrapper<>();
        ew.orderBy("sort");
        List<BaseProgressType> list = progressTypeService.selectList(ew);

        for (BaseProgressType info : list) {
            EntityWrapper<BaseProgress> ew_progress = new EntityWrapper<>();
            ew_progress.orderBy("sort");
            List<BaseProgress> progresses = progressService.selectList(ew_progress);
            if (progresses != null && progresses.size() > 0) {
                info.setList(progresses);
            }
        }
        return new ReturnObject<>(0, "获取成功", list);
    }

}

